import socket

users = {"hst": "070402","pyx": "070202","gxy": "070130",'lkq':'070302'}

def run_server():
    s = socket.socket()
    s.bind(('localhost', 8888))
    s.listen(1)
    conn, addr = s.accept()

    data = conn.recv(1024).decode()
    username, password = data.split(':')

    if username in users and users[username] == password:
        conn.send("登陆成功".encode())
    else:
        conn.send("登陆失败".encode())
    conn.close()


def run_client():
    s = socket.socket()
    s.connect(('localhost', 8888))
    username = input("用户名: ")
    password = input("密码: ")
    s.send(f"{username}:{password}".encode())
    reply = s.recv(1024).decode()
    print("服务器回复：", reply)
    s.close()

if __name__ == "__main__":
    run_server()
    # print("1：服务器")
    # print("2：客户端")
    # choice = input("请选择（1/2）： ")
    #
    # if choice == "1":
    #     run_server()
    # elif choice == "2":
    #     run_client()
    # else:
    #     print("你只能选择1或2")